precision mediump float;

varying vec2 v_textcoordL;
varying vec3 v_normal;
varying vec3 v_pos;

uniform sampler2D u_texture;
uniform vec3 a_camPos;
uniform mat4 u_transformMatrix;

void main()
{
	vec4 objCol = vec4(1.0, 1.0, 1.0, 1.0);//texture2D(u_texture, v_textcoordL);
	vec4 diffCol = vec4(1.0, 1.0, 1.0, 1.0);
	vec4 ambCol = vec4(1.0, 1.0, 1.0, 1.0);
	vec4 specCol = vec4(0.7, 0.7, 0.7, 1.0);
	float weight = 0.2;

	vec3 lightPos = vec3(0.0, 0.0, 10.0);
	vec3 lightDir = normalize(v_pos - lightPos);
	vec3 ref = reflect(normalize(lightDir),normalize(v_normal));
	vec3 toEye = normalize(a_camPos - v_pos);
	
	float dotL = dot(v_normal, -lightDir);
	float dotR = dot(ref, toEye);
	
	vec4 diff = objCol*diffCol*max(dotL, 0.0);
	vec4 amb = objCol*ambCol;
	vec4 spec = pow(max(dotR, 0.0), 32.0)*specCol;
	
	gl_FragColor = (1.0 - weight)*diff + weight*amb + spec;
}
